using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WebControls;
using EntityLayer;
using BusinessLayer;
using InfraStructureLayer;

public partial class Admin_Languages : SFPage
{
    entLanguages insEntLanguages = new entLanguages();
    busLanguages insBusLanguages = new busLanguages();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected bool sfgLanguages_NeedsDataSource()
    {
        sfgLanguages.SetData(CurrentContext.Languages);
        return false;
    }
    protected void btnNew_Click(object sender, EventArgs e)
    {
        this.Id = 0;
        this.OpenEditPanel();
    }
    protected void sfgLanguages_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "EditData")
        {
            this.Id = Convert.ToInt32(e.CommandArgument);
            this.OpenEditPanel();
        }
        else if (e.CommandName == "DeleteData")
        {
            insEntLanguages.LanguageId = Convert.ToInt32(e.CommandArgument);
            insBusLanguages.DeleteLanguagesByLanguageId(insEntLanguages);
            if (insBusLanguages.HasErrors)
            {
                MessageBoxShow(insBusLanguages);
                return;
            }
            CurrentContext.Languages = null;
            this.LoadLanguages();
            sfgLanguages.LoadGridData();
            this.CloseEditPanel();
        }
    }
    public override void OpenEditPanel()
    {
        this.Clear(this.Master.FindControl("ContentPlaceHolderEdit"));
        base.OpenEditPanel();
        FillEditPanel();
    }
    private void FillEditPanel()
    {
        if (this.Id != 0)
        {
            insEntLanguages.LanguageId = this.Id;
            insBusLanguages.SelectLanguagesByLanguageId(insEntLanguages);
            txtLanguageName.Text = insEntLanguages.LanguageName;
            txtLanguageCulture.Text = insEntLanguages.LanguageCulture;
        }
        else
        {
            txtLanguageName.Text = "";
            txtLanguageCulture.Text = "";
        }
    }

    public override void Save()
    {
        this.Validate();
        if (this.HasErrors)
        {
            MessageBoxShow(this);
            return;
        }
        insEntLanguages.LanguageCulture = txtLanguageCulture.Text;
        insEntLanguages.LanguageName = txtLanguageName.Text;
        base.Save();
    }
    public override void SaveNew()
    {
        insBusLanguages.InsertLanguages(insEntLanguages);
        if (insBusLanguages.HasErrors)
        {
            MessageBoxShow(insBusLanguages);
            return;
        }
        base.SaveNew();
        CurrentContext.Languages = null;
        this.LoadLanguages();
        sfgLanguages.LoadGridData();
    }
    public override void SaveExisting()
    {
        insEntLanguages.LanguageId = this.Id;
        insBusLanguages.UpdateLanguagesByLanguageId(insEntLanguages);
        if (insBusLanguages.HasErrors)
        {
            MessageBoxShow(insBusLanguages);
            return;
        }
        base.SaveExisting();
        CurrentContext.Languages = null;
        this.LoadLanguages();
        sfgLanguages.LoadGridData();
    }
}
